package com.heima.article.controller;

import com.heima.article.entity.ApAuthor;
import com.heima.article.service.ApAuthorService;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.dtos.AuthorDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
public class AuthorController {

    @Autowired
    private ApAuthorService authorService;

    /**
     * 用户审核通过以后，feign调用，创建文章的作者
     *
     */
    @PostMapping("/api/v1/author/save")
    public Integer createAuthor(@RequestBody AuthorDto dto){
        return authorService.createAuthor(dto);
    }

    /**
     * feign接口调用
     * @param userId
     * @return
     */
    @GetMapping("/api/v1/author/getAuthorByUserId")
    public ApAuthor getAuthorByUserId(Integer userId){
        return authorService.getAuthorByUserId(userId);
    }


    /**
     * 这是一个feign接口，根据id查询详情
     * */
    @GetMapping("/api/v1/author/findById/{id}")
    public AuthorDto findById(@PathVariable("id")Long id){
        return authorService.findById(id);
    }
}
